import LineMaterialProperty from '../../lib/LineMaterialProperty'
import el from 'element-ui/src/locale/lang/el'
/**
 * 专题图层 - 需防洪治理山洪沟
 */
export default {
    data() {
        return {

        }
    },
    computed: {
        basin() {
            return this.$store.getters.basin
        }
    },
    watch: {
        basin: {
            handler: function(name) {
                this.$nextTick(() => {
                    this.creatXFHZLSHG(name)
                })
            },
            immediate: true
        }
    },
    created() {
        this._dataSourceXFHZLSHG = null
    },
    methods: {
        creatXFHZLSHG(name) {
            this.clearXFHZLSHG()
            if (this.layerList2[1].children.XFHZLSHG.show) {
                this._dataSourceXFHZLSHG = new Cesium.CustomDataSource('PolylineDataSource')
                var url = `${mapConfig.resUrlPre}/geojson/${this.basin}/XFHZLSHG.json`
                this.$axios.get(url).then(res => {
                    console.log(res.data.features)
                    res.data.features.forEach(feature => {
                        var lonlats = []
                        if (feature.geometry.type === 'LineString') {
                            feature.geometry.coordinates.forEach(coordinate => {
                                lonlats.push(...coordinate)
                            })
                        } else if (feature.geometry.type === 'MultiLineString') {
                            feature.geometry.coordinates.forEach(coordinates => {
                                coordinates.forEach(coordinate => {
                                    lonlats.push(...coordinate)
                                })
                            })
                        } else {
                            console.log('An error occurred')
                        }

                        var _image = this.layerList2[1].children.XFHZLSHG.icon
                        var repeat = feature.properties['SHAPE_Le_1']
                        var lineMaterialProperty = new LineMaterialProperty({
                            image: _image,
                            duration: 4000,
                            color: Cesium.Color.fromCssColorString('#ff0000').withAlpha(1),
                            repeat: repeat * 1000
                            // repeat: repeat * 500
                        })
                        var polylineEntity = {
                            polyline: {
                                positions: Cesium.Cartesian3.fromDegreesArray(lonlats),
                                width: 5,
                                material: Cesium.Color.RED,
                                clampToGround: true,
                                classificationType: Cesium.ClassificationType.BOTH // BOTH  or TERRAIN
                            }
                        }
                        this._dataSourceXFHZLSHG.entities.add(polylineEntity)
                    })
                    this.$viewer.dataSources.add(this._dataSourceXFHZLSHG)
                })
            } else {
                this.clearXFHZLSHG()
            }
        },

        clearXFHZLSHG() {
            if (this._dataSourceXFHZLSHG) this.$viewer.dataSources.remove(this._dataSourceXFHZLSHG)
        }
    }
}
